package cn.com.nxt.txb.adapter;

import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;

import cn.com.nxt.txb.BaseActivity;
import cn.com.nxt.txb.LoginActivity;
import cn.com.nxt.txb.R;
import cn.com.nxt.txb.util.AppConstant;
import cn.com.nxt.txb.util.AppUtil;

public class ViewFlowAdapter extends BaseAdapter {
	private FragmentActivity mContext;
	private LayoutInflater mInflater;
	protected SharedPreferences.Editor mEditor;
	protected SharedPreferences mSettings;

	public ViewFlowAdapter(FragmentActivity context) {
		mContext = context;
		mInflater = LayoutInflater.from(mContext);
		mSettings = mContext.getSharedPreferences(AppConstant.USERINFO,
				mContext.MODE_PRIVATE);
		mEditor = mSettings.edit();
	}

	@Override
	public int getCount() {
		return 3;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.viewflow_item, null);
		}
		ImageView mIV = (ImageView) convertView.findViewById(R.id.iv_img);
		LinearLayout mIVExperience = (LinearLayout) convertView
				.findViewById(R.id.ll_experience);
		if (position == 0) {
			if (mIVExperience.getVisibility() == View.VISIBLE)
				mIVExperience.setVisibility(View.GONE);
			mIV.setImageResource(R.drawable.lead1);
		} else if (position == 1) {
			if (mIVExperience.getVisibility() == View.VISIBLE)
				mIVExperience.setVisibility(View.GONE);
			mIV.setImageResource(R.drawable.lead2);
		} else {
			if (mIVExperience.getVisibility() == View.GONE)
				mIVExperience.setVisibility(View.VISIBLE);
			mIV.setImageResource(R.drawable.lead3);
		}
		mIVExperience.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				mEditor.putBoolean(AppUtil.SETTING_ISFIRST, false);
				mEditor.commit();
				Intent intent = new Intent(mContext, LoginActivity.class);
				// intent.putExtra(BaseActivity.SETTING_INTEGRAL_POLICY, true);
				mContext.startActivity(intent);
				mContext.finish();
				// (FragmentActivity)mContext.finish();
			}
		});
		return convertView;
	}
}
